package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.common.base.SetAndModifyModel;
import com.jy.wms.common.base.SucessException;
import com.jy.wms.dao.WmsEstimatedArrivalOrderDetailedMapper;
import com.jy.wms.pojo.WmsEstimatedArrivalOrderDetailed;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
* @ClassName: WmsEstimatedArrivalOrderDetailedService.java
* @Description: TODO(这里用一句话描述这个类的作用)
* @Author Liyi
* @Date Wed Sep 27 09:49:11 CST 2017
*/

@Service
public class WmsEstimatedArrivalOrderDetailedService extends BaseService<WmsEstimatedArrivalOrderDetailedMapper,WmsEstimatedArrivalOrderDetailed> {


 /**
 * 插入一条记录
 * @param entity 实体对象
 * @return int
 */
public Integer baseInsert(WmsEstimatedArrivalOrderDetailed entity ){
     return dao.baseInsert( entity );
}

/**
* 插入一条记录（匹配有值的字段）
* @param entity 实体对象
* @return int
*/
@BaseServiceDescribe(moduleName = "预期到货通知单明细",btnName = "新增预期到货通知单明细")
public Integer baseInsertSelective( WmsEstimatedArrivalOrderDetailed entity )throws SucessException,ServiceException{
        entity.setId(UUIDUtils.uuid());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        entity.setScrq(formatter.format(new Date(Integer.valueOf(entity.getScrq()))));
        entity.setSxrq(formatter.format(new Date(Integer.valueOf(entity.getSxrq()))));
        if(entity.getBz() == null){
            entity.setBz("");
        }
        Integer addCount = dao.baseInsertSelective( entity );
        if(addCount>0){
            entity = dao.selectById(entity.getId());
            throw new SucessException("新增预期到货通知单明细成功");
        }else{
            throw new ServiceException("新增预期到货通知单明细失败，未插入数据库");
        }
}

/**
* 删除（根据主键ID删除）
* @param id 主键
* @return int
*/
public Integer baseDeleteByPrimaryKey( String id ){
     return dao.baseDeleteByPrimaryKey( id );
}

/**
* 删除（根据ID 批量删除）
* @param idList 主键ID列表
* @return int
*/
public Integer baseDeleteBathPrimaryKeys( List<String> idList ){
     return dao.baseDeleteBathPrimaryKeys( idList );
}

/**
* 分页查询
* @param entity 实体
* @return Page<WmsEstimatedArrivalOrderDetailed>
*/
public Page<WmsEstimatedArrivalOrderDetailed> baseSelectPage(WmsEstimatedArrivalOrderDetailed entity ){
    PageHelper.startPage(entity.getPage(),entity.getRows());
    return (Page<WmsEstimatedArrivalOrderDetailed>)dao.baseSelectPage( entity );
}

/**
* 查询（根据主键ID查询）
* @param id 主键ID
* @return WmsEstimatedArrivalOrderDetailed
*/
public WmsEstimatedArrivalOrderDetailed baseSelectByPrimaryKey( String id ){
     return dao.baseSelectByPrimaryKey( id );
}

/**
 * 查询（根据ssyqdid所属预期到货单ID查询）
 * @param ssyqdid 所属预期到货单ID
 * @return
 */
@BaseServiceDescribe(moduleName = "预期到货通知单明细",btnName = "根据预期到货通知单ID查询所属预期到货通知单明细")
public List<WmsEstimatedArrivalOrderDetailed> getBySsyqdid(String ssyqdid) throws ServiceException{
    try {
        return dao.getBySsyqdid(ssyqdid);
    } catch (Exception e) {
        e.printStackTrace();
        throw new ServiceException("根据预期到货通知单ID查询所属预期到货通知单明细");
    }
}

/**
 * 查询（根据主键ID查询）
 * @param ssyqdid 所属预期到货单ID
 * @return WmsEstimatedArrivalOrderDetailed
 */
public List<WmsEstimatedArrivalOrderDetailed> baseSelectBySsyqdid( String ssyqdid ){
    return dao.baseSelectBySsyqdid( ssyqdid );
}

/**
* 查询（根据ID 批量查询）
* @param idList 主键ID列表
* @return list
*/
public Integer baseSelectBathPrimaryKeys( List<WmsEstimatedArrivalOrderDetailed> idList ){
     return dao.baseSelectBathPrimaryKeys( idList );
}

/**
*修改 （匹配有值的字段）
* @param entity 主键ID列表
* @return int
*/
@BaseServiceDescribe(moduleName = "预期到货通知单明细",btnName = "修改预期到货通知单明细")
public Integer baseUpdateByPrimaryKeySelective( WmsEstimatedArrivalOrderDetailed entity )throws SucessException,ServiceException{
     Integer editCount = dao.baseUpdateByPrimaryKeySelective( entity );
     if(editCount>0){
         throw new SucessException("修改预期到货通知单明细成功");
     }else{
         throw new ServiceException("修改预期到货通知单明细失败,未插入数据库");
     }
}

/**
*修改（根据主键ID修改）
* @param entity 主键ID列表
* @return int
*/
public Integer baseUpdateByPrimaryKey( WmsEstimatedArrivalOrderDetailed entity ){
     return dao.baseUpdateByPrimaryKey( entity );
}
    /**
     *查询ASN码盘信息 （根据预期到货通知单ID查询）
     * @param ssyqdid 预期到货通知单ID
     * @return int
     */
    @BaseServiceDescribe(moduleName = "ASN码盘",btnName = "分页查询码盘信息")
    public List<WmsEstimatedArrivalOrderDetailed> seachASNBySsyqdid(String ssyqdid)throws Exception{
        try{
            return dao.seachASNBySsyqdid(ssyqdid);
        }catch (Exception e){
            throw new ServiceException("查询ASN码盘信息失败",e);
        }

    }

    @BaseServiceDescribe(moduleName = "预期到货通知单明细",btnName = "删除预期到货通知单明细")
    public void delete(SetAndModifyModel setAndModifyModel)throws SucessException,ServiceException{
       Integer delCount = dao.delAsn(setAndModifyModel.getIds());
       if(delCount>0){
           throw new SucessException("选中明细"+setAndModifyModel.getIds().size()+"条，删除成功"+delCount+"条");
       }else{
           throw new ServiceException("删除预期到货通知单明细成功,未插入数据库");
       }
    }
}
